package com.scarecrow.compack.component.view {

	import com.scarecrow.compack.family.IDisplayComponent;
	import com.scarecrow.olga.game.component.UpdateableComponent;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	/**
	 * This basic component contains and updates a displayObject
	 * according to its owner's position.
	 * ...
	 * @author Santiago.J.Elizalde
	 */
	public class BaseDisplay extends UpdateableComponent implements IDisplayComponent {
		
		protected var _display:DisplayObject;
		protected var position:Point;
		protected var _displayClass:Class;
		
		public function BaseDisplay() {
			
		}
		
		override protected function initialize():void {
			//_stage.addChild(display);
		}
		
		override public function update(ms:uint = 0):void {
			
			if (position) {
				display.x = position.x;
				display.y = position.y;
			} else {
				if (owner.hasProp("pos")) {
					position = owner.getProp("pos") as Point;
					display.x = position.x;
					display.y = position.y;
				}
			}
		}
		
		public function get displayClass():Class {
			return _displayClass;
		}
		
		public function set displayClass(value:Class):void {
			_displayClass = value;
			_display = new _displayClass() as DisplayObject;
		}
		
		public function get display():DisplayObject {
			return _display;
		}
		
		override protected function releaseGameObject():void {
			this.enabled = false;
		}
	}

}